<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/jsp/commons/taglibs.jsp" %>
<!DOCTYPE HTML>
<html ng-app>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
    <title>${title}</title>
    <%@ include file="/WEB-INF/jsp/commons/meta.jsp" %>
    <link href="${ctx}/resources/new/style.css" type="text/css" rel="stylesheet"/>

</head>
<body>
<form id="inputForm" class="well form-inline" action="${ctx}/adoms/order/deal" method="post">
    <input type="hidden" name="id" value="${order.id}"/>
    <textarea class="hide" name="logs">${order.logs}</textarea>
    <input id="type" name="type" type="hidden" value="1"/>
    <input name="boxNumber" type="hidden" value="${order.boxNumber }"/>
    <table class="table table-striped table-bordered table-condensed">
        <thead>
        <i class="icon-flag"></i>
        <strong>订单处理</strong>
        </thead>
        <tr>
            <td class="span2">订单编号:</td>
            <td>
                <span class="tBlue">${order.code}</span>
                <input id="code" name="code" type="hidden" value="${order.code}" size="30" maxlength="80"/>
            </td>
        </tr>
        <tr class="hide">
            <td class="span2">订单名称:</td>
            <td>
                <span class="tBlue">${order.name}</span>
                <input id="name" class="span4" name="name" type="hidden" value="${order.name}" size="30"
                       maxlength="80"/>
            </td>
        </tr>
        <tr>
            <td>下单时间:</td>
            <td>
				<span class="tBlue">
					<fmt:formatDate value="${order.orderCreateTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
				</span>
                <input datepicker id="orderCreateTime" name="orderCreateTime" type="hidden"
                       value="${order.orderCreateTime}" size="30" maxlength="80"/>
            </td>
        </tr>
        <tr>
            <td>商品定购详情：</td>
            <td>
                <input type="hidden" name="orderInfo" value="${order.orderInfo}"/>

                <div id="mInfo"></div>
            </td>
        </tr>
        <tr>
            <td>订购总数量:</td>
            <td>
				<span class="tRed">
					<fmt:formatNumber value="${order.boxNumber}" pattern="###,##0.00"></fmt:formatNumber>
				</span>
                件
                <input id="goodsNumber" class="span1" name="goodsNumber" type="hidden" value="${order.goodsNumber}"
                       size="30" maxlength="4"/>
            </td>
        </tr>
        <tr>
            <td>订单总价:</td>
            <td>
				<span class="tRed">
					<fmt:formatNumber value="${order.totalCost}" pattern="###,###.##"></fmt:formatNumber>
				</span>
                元
                <input id="totalCost" name="totalCost" class="span2" readonly="readonly" type="hidden"
                       value="${order.totalCost}" size="30" maxlength="8"/>
            </td>
        </tr>
        <tr>
            <td>收货部门:</td>
            <td>
                <span class="tBlue">${order.department.name}</span>
                <input id="department" name="department.id" type="hidden" value="${order.department.id}" size="30"
                       maxlength="80"/>
            </td>
        </tr>
        <tr>
            <td>联系人:</td>
            <td>
                <span class="tBlue">${order.createUser}</span>
                <input id="createUser" name="createUser" type="hidden" value="${order.createUser}" size="30"
                       maxlength="80"/>
            </td>
        </tr>
        <tr>
            <td>联系电话:</td>
            <td>
                <span class="tBlue">${order.phone}</span>
                <input id="phone" name="phone" type="hidden" value="${order.phone}" size="30" maxlength="80"/>
            </td>
        </tr>
        <tr>
            <td>订购备注:</td>
            <td>
                <div class="tBlue">${order.memo}</div>
                <textarea id="memo" name="memo" rows="4" class="span6 hide">${order.memo}</textarea>
            </td>
        </tr>
        <tr>
            <td>更新状态:</td>
            <td>
                <select id="status" name="status">
                    <option value="ORDER_WILL_SHIP" <c:if
                            test="${order.status == 'ORDER_WILL_SHIP' }"> selected </c:if>>待发货
                    </option>
                    <option value="ORDER_HAS_SHIPED" <c:if
                            test="${order.status == 'ORDER_HAS_SHIPED' }"> selected </c:if>>已发货
                    </option>
                    <option value="ORDER_HAS_CANCELED" <c:if
                            test="${order.status == 'ORDER_HAS_CANCELED' }"> selected </c:if>>取消订单
                    </option>
                </select>
            </td>
        </tr>
        <c:if test="${not empty(order.receivedTime) }">
            <tr>
                <td>上次处理时间:</td>
                <td>
					<span class="tBlue">
						<fmt:formatDate value="${order.receivedTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
					</span>
                </td>
            </tr>
        </c:if>
        <tr>
            <td>订单受理人:</td>
            <td>
                <input id="orderChargeUser" name="orderChargeUser" type="text"
                       value="${empty(order.orderChargeUser) ? USER.name:order.orderChargeUser}" size="30"
                       maxlength="80"/>
            </td>
        </tr>
        <tr>
            <td>发货部门:</td>
            <td>
                <span class="tBlue">${order.departmentTarget.name}</span>
                <input id="departmentTarget" name="departmentTarget.id" type="hidden"
                       value="${order.departmentTarget.id}" size="30" maxlength="80"/>
            </td>
        </tr>
        <tr>
            <td valign="top">订单状态:</td>
            <td>
                <table class="table table-striped table-bordered table-condensed">
                    <tr class="tBlue">
                        <th>#</th>
                        <th>时间</th>
                        <th>订单状态</th>
                        <th>部门</th>
                        <th>操作员</th>
                        <th>操作内容</th>
                    </tr>
                    <c:forEach items="${order.logsMap }" varStatus="i" var="entry">
                        <tr>
                            <c:set value="${entry.value }" var="ob">
                            </c:set>
                            <td>${i.index + 1}</td>
                            <td>${ob['date']}</td>
                            <td>${ob["status"] }</td>
                            <td>${ob["department"]}</td>
                            <td>${ob["user"] }</td>
                            <td>${ob["msg"] }</td>
                        </tr>
                    </c:forEach>
                </table>
            </td>
        </tr>
        <tr>
            <td valign="top">备注:</td>
            <td>
                <textarea id="memo2" name="memo2" rows="4" class="span6" maxlength="200">${order.memo2}</textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center" class="text-center">
                <input class="btn btn-primary span1" type="submit" value="提 交"/>
                &nbsp;
                <input class="btn span1 btn-info" type="button" value="返 回" back="back" onclick="history.go(-1)"/>
            </td>
        </tr>
        <tr>
            <td colspan="2" class="hide">
                <input name="memo3" value="${order.memo3 }"/>
                <input name="outUser" value="${order.outUser }"/>
                <c:if test="${not empty(order.outTime ) }">
                    <input name="outTime" value="${order.outTime }"/>
                </c:if>
            </td>
        </tr>
    </table>
</form>
<script>
    $(document).ready(function () {
        //为inputForm注册validate函数
        $("#inputForm").validate({
            rules: {
                totalCost: "required",
                phone: "required",
                orderCreateTime: "required",
                status: "required",
                department: "required",
                memo: "required",
                departmentTarget: "required",
                createUser: "required",
                memo2: "required",
                goodsNumber: {
                    required: true,
                    number: true
                }
            }
        });
        //计算总价
        $("#goodsNumber").keyup(function () {
            var number = parseInt($(this).val());
            var price = parseFloat($("#mPrice").html());
            var cost = number * price;
            $("#totalCost").val(cost.toFixed(2));
        });
        $("#mInfo").load("${ctx}/adoms/orderLine/list/${order.id} #dataList", function () {
            $("#dataList tr").each(function () {
                $("th:eq(1)", this).remove();
                $("th:last", this).remove();
                $("td:eq(1)", this).remove();
                $("td:last", this).remove();
                $(".showed", this).show();
                $(".showed a", this).click(function () {
                    var url = $(this).attr("href");
                    $("#changeOrderLineNumber #orderLineContent").load(url, function () {
                        $("#inputForm2 #flag").val("deal");
                        $("#inputForm2 [back]").click(function () {
                            $("#changeOrderLineNumber").modal("hide");
                            return false;
                        }).val("关闭").removeAttr("onclick");
                        $("#inputForm2 input:submit").click(function () {
                            $("#changeOrderLineNumber").modal("hide");
                        });
                        $("#changeOrderLineNumber").modal("show");
                    });
                    return false;
                });
            });
        });
        $(".modal-header").mousedown(function () {
            $(this).css("cursor", "move");
            $("#changeOrderLineNumber").draggable();
            $("#changeOrderLineNumber").draggable("option", "disabled", false);
        }).mouseup(function () {
            $(this).css("cursor", "auto");
            $("#changeOrderLineNumber").draggable("option", "disabled", true);
        });
    });
</script>
<div class="modal fade hide" id="changeOrderLineNumber" style="width: 600px; height: auto;">
    <div class="modal-header">
        <a class="close" data-dismiss="modal">×</a>
        <h5>
            <i class="icon-comment"></i>
            商品订购数量-修改
        </h5>
    </div>
    <div class="modal-body" id="orderLineContent"></div>
</div>
</body>
</html>